package com.test.daily.leetcode.y2022.m06.day0614.v11;

import java.util.LinkedList;

/**
 * @author Tom on 2022/6/14
 */
public class Solution {
    public static int[] maxWindows(int[] arr, int w){
        if(arr == null || arr.length == 0){
            return null;
        }
        int[] maxArray = new int[arr.length - w + 1];
        LinkedList<Integer> qMax = new LinkedList<>();
        int i = 0;
        for (int R = 0; R < arr.length; R++) {
            while(qMax.size() != 0 && qMax.peek() <= arr[R]){
                qMax.pollLast();
            }
            qMax.add(R);
            if(R - qMax.peek() == w){
                qMax.peekFirst();
            }
            if(R >= w-1){
                arr[i++] = qMax.peekFirst();
            }
        }
        return arr;
    }
}
